package grpcsvc

import (
	"publiclib/grpcutil"

	pb "generatorserver/internal/protobuf"

	"google.golang.org/grpc"
)

// 服务处理
type ServiceMux struct{}

func (ServiceMux) RegisterService(svc *grpc.Server) {
	pb.RegisterGeneratorServer(svc, &generatorServer{})
	pb.RegisterOTPServer(svc, &OTPServer{})
}

// 加载一份tls
func LoadLexarGRPCServerTlsConf(certFile, keyFile string) *grpcutil.LexarGRPCServerConf {
	cert := grpcutil.LoadRpcServerCertFile(certFile, keyFile)
	return &grpcutil.LexarGRPCServerConf{
		TlsEnable: true,
		Tc:        cert,
	}
}

// 加载一份tls, 证书为p12格式
func LoadLexarGRPCServerTlsConfV2(certFile, certPwd string) *grpcutil.LexarGRPCServerConf {
	cert := grpcutil.LoadRpcServerP12CertFile(certFile, certPwd)
	return &grpcutil.LexarGRPCServerConf{
		TlsEnable: true,
		Tc:        cert,
	}
}

// 此处与impl相匹配， 可以多个service对象
func GRPCServerStart(conf *grpcutil.LexarGRPCServerConf) error {
	return grpcutil.StartGRPCServer(conf, ServiceMux{})
}
